using System;
using System.Collections.Generic;
using System.Windows.Browser;

namespace HtmlUtilities.UITest
{
    public static class PageCommands
    {
        public static IEnumerable<Command<string>> GetCommands()
        {
            return new List<Command<string>>
                       {
                           new Command<string>("IsEnabled", () => Html.Page.IsEnabled.ToString()),
                           new Command<string>("IsPopupWindowAllowed", () => Html.Page.IsPopupWindowAllowed.ToString()),
                           new Command<string>("Plugin", () => Html.Page.Plugin.Id),
                           new Command<string>("PopupWindow", PopupWindow),
                           new Command<string>("RegisterCreatableType", RegisterCreatableType),
                           new Command<string>("RegisterScriptableObject", () => "See ScriptObject.ManagedObject test"),
                           new Command<string>("UnregisterCreateableType", UnregisterCreateableType)
                       };
        }

        private static string UnregisterCreateableType()
        {
            Html.Page.UnregisterCreateableType("SLName");
            try
            {
                var name = Html.Page.Window.Invoke("CreateSLName", "Brian", "Genisio") as IScriptObject;
            }
            catch (Exception)
            {
                return "Succesfully unregistered";
            }

            return "Unsuccessfully Unregistered";
        }

        [ScriptableType]
        public class Name
        {
            public string First { get; set; }
            public string Last { get; set; }
            public override string ToString()
            {
                return First + " " + Last;
            }
        }

        private static string RegisterCreatableType()
        {
            Html.Page.RegisterCreateableType("SLName", typeof(Name));
            var name = Html.Page.Window.Invoke("CreateSLName", "Brian", "Genisio") as IScriptObject;
            return name.ManagedObject.ToString();
        }

        private static string PopupWindow()
        {
            Html.Page.PopupWindow(new Uri("http://www.cnn.com"), "_blank",
                                  new HtmlPopupWindowOptions { Height = 100, Width = 100 });

            return "Created New Popup";
        }
    }
}